import type { Plugin } from 'vite'
import { viteMockServe } from 'vite-plugin-mock'

// [mock虚拟数据服务](https://github.com/vbenjs/vite-plugin-mock)
export default (options?:viteUserOptions) => {
    //真实的生产项目打包时请关闭，会影响打包体积
    let prodMock = true
    return {
        plugins: viteMockServe({
            // default mock path
            mockPath: 'mock',
            localEnabled: !options.isBuild,
            prodEnabled: options.isBuild && prodMock,
            //  这样可以控制关闭mock的时候不让mock打包到最终代码内
            injectCode: `
                import { setupProdMockServer } from '../mock/_mockProdServer';
                setupProdMockServer();
            `,
            ignore: /^\_/,
            logger: true,
        })
    }
}